//
//  StatusCell.m
//  lvtu
//
//  Created by Apple on 12-4-3.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "StatusCell.h"

@implementation StatusCell
@synthesize userImageView;
@synthesize tripImageView;
@synthesize cellHeight;
@synthesize m_index;
@synthesize delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        isNeedLoad = NO;
        userImageView = [[EGOImageView alloc] initWithFrame:
                         CGRectMake(0, 0, 70, 70)];
        //userImageView.image = [UIImage imageNamed:@"bg_user_default.png"];
        [userImageView setPlaceholderImage:[UIImage imageNamed:@"bg_user_default.png"]];
        [self addSubview:userImageView];
        
        tripImageView = [[EGOImageView alloc] initWithFrame:
                         CGRectMake(70, 0, 288-70, 70)];
        //tripImageView.image = [UIImage imageNamed:@"bg_trip_default.png"];
        [tripImageView setPlaceholderImage:[UIImage imageNamed:@"bg_trip_default.png"]];
        [self addSubview:tripImageView];
        
        creattimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 73, 65, 20)];
        creattimeLabel.text = @"2012-03-12";
        creattimeLabel.backgroundColor = [UIColor clearColor]; 
        //creattimeLabel.textColor = [UIColor blackColor];
        creattimeLabel.font = [UIFont systemFontOfSize:12.0f];
        creattimeLabel.numberOfLines = 0;
        creattimeLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:creattimeLabel];
        
        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(65, 72, 100, 22)];
        nameLabel.text = @"浪漫之旅";
        nameLabel.backgroundColor = [UIColor clearColor]; 
        //nameLabel.textColor = [UIColor blackColor];
        nameLabel.font = [UIFont systemFontOfSize:14.0f];
        nameLabel.numberOfLines = 0;
        nameLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:nameLabel];
        
        likeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(288-120, 76, 15, 16)];
        likeImageView.image = [UIImage imageNamed:@"icn_like.png"];
        [self addSubview:likeImageView];
        
        likeCount = [[UILabel alloc]initWithFrame:CGRectMake(288-103, 76, 25, 16)];
        likeCount.text = @"0";
        likeCount.backgroundColor = [UIColor clearColor]; 
        //likeCount.textColor = [UIColor blackColor];
        likeCount.font = [UIFont systemFontOfSize:12.0f];
        likeCount.numberOfLines = 0;
        likeCount.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:likeCount];
        
        collectImageView = [[UIImageView alloc] initWithFrame:CGRectMake(288-80, 76, 15, 16)];
        collectImageView.image = [UIImage imageNamed:@"icn_collect.png"];
        [self addSubview:collectImageView];
        
        collectCount = [[UILabel alloc]initWithFrame:CGRectMake(288-63, 76, 25, 16)];
        collectCount.text = @"0";
        collectCount.backgroundColor = [UIColor clearColor]; 
        //collectCount.textColor = [UIColor blackColor];
        collectCount.font = [UIFont systemFontOfSize:12.0f];
        collectCount.numberOfLines = 0;
        collectCount.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:collectCount];
        
        commentImageView = [[UIImageView alloc] initWithFrame:CGRectMake(288-40, 76, 15, 16)];
        commentImageView.image = [UIImage imageNamed:@"icn_comment.png"];
        [self addSubview:commentImageView];
        
        commentCount = [[UILabel alloc]initWithFrame:CGRectMake(288-23, 76, 25, 16)];
        commentCount.text = @"0";
        commentCount.backgroundColor = [UIColor clearColor];
        //collectCount.textColor = [UIColor blackColor];
        commentCount.font = [UIFont systemFontOfSize:12.0f];
        commentCount.numberOfLines = 0;
        commentCount.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:commentCount];
        
        [self setUserInteractionEnabled:YES];

        statusButton = [[UIButton alloc] initWithFrame:CGRectMake(240, 20, 40, 40)];
        [statusButton setBackgroundImage:[UIImage imageNamed:@"btn_delete_normal.png"] forState:UIControlStateNormal];
        [statusButton setBackgroundImage:[UIImage imageNamed:@"btn_delete_press.png"] forState:UIControlStateSelected];
        [statusButton addTarget:self action:@selector(delButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        //    [self.contentView addSubview:statusButton];
    }
    return self;
}

- (void)setImageViewCell:(RecommendTripInfo*) info
{
    if (isNeedLoad == NO) {
        if (info.memberid && ![info.memberid isEqualToString:@""]) {
            [userImageView setImageURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.wxlvtu.com/img.php?filename=%@",info.membericon]]];
        }
        else {
            [userImageView setImage:[UIImage imageNamed:@"bg_user_default.png"]];
        }
        if (info.coverurl && ![info.coverurl isEqualToString:@""]) {
            [tripImageView setImageURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.wxlvtu.com/img.php?filename=%@",info.coverurl]]];
        }
        else {
            [tripImageView setImage:[UIImage imageNamed:@"bg_trip_default.png"]];
        }
        isNeedLoad = NO;
    }
    
    if (info.creattime == nil) {
        creattimeLabel.text = @"2012-04-04";
    }
    else
    {
        creattimeLabel.text = info.creattime;
    }
    nameLabel.text = info.name;
    if (info.favorcount == nil) {
        likeCount.text = @"0";
    }
    else
    {
        if ([info.praisecount intValue] > 99) {
            likeCount.text = @"99+";
        }
        else
        {
            likeCount.text = info.praisecount;
        }
    }
    if (info.praisecount == nil) {
        collectCount.text = @"0";
    }
    else
    {
        if ([info.favorcount intValue] > 99 ) {
            collectCount.text = @"99+";
        }
        else
        {
            collectCount.text = info.favorcount;
        }
    }
    if (info.commentcount == nil) {
        commentCount.text = @"0";
    }
    else
    {
        if ([info.commentcount intValue] > 99) {
            commentCount.text = @"99+";
        }
        else
        {
            commentCount.text = info.commentcount;
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    //[super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)delButtonPressed
{
    [delegate touchUpDelCellButton:m_index];
}

- (void)delButton:(BOOL)isAdd
{
    if (isAdd) {
        [self addSubview:statusButton];
    }
    else {
        [statusButton removeFromSuperview];
    }
}

- (void)dealloc {
    [userImageView release]; userImageView = nil;
    [tripImageView release]; tripImageView = nil;
    [collectImageView release]; collectImageView = nil;
    [likeImageView release]; likeImageView = nil;
    
    [creattimeLabel release]; creattimeLabel = nil;
    [nameLabel release]; nameLabel = nil;
    
    [collectCount release]; collectCount = nil;
    [likeCount release]; likeCount = nil;
    [super dealloc];
}
@end
